<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
	                   			<td>
		                   			<form class="form-inline" onsubmit="return false">
										<div class="form-group">
											sku：
											<input id="sku" type="text" class="form-control">
											<button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>
										</div>
									</form>
	                   			</td>
	                   			<td align="right">
	                   				<button class="layui-btn layui-btn-sm" onclick="saveOrderItems()">
                                       确认提交
                                    </button>

                                    <button class="layui-btn layui-btn-sm" onclick="resetForm()">
                                       取消
                                    </button>
	                   			</td>
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th>id</th>
									<th>商品编号</th>
									<th>sku</th>
                                    <th>商品名称</th>
									<th>库存</th>
									<th>单位</th>
									<th>创建时间</th>
									<th>更新时间</th>
									<th>盘点库存</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
    <script type="text/javascript" src="../../js/common.js"></script>

<script type="text/javascript">
var pers = checkPermission();

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/pGoodsStocks",
        		"type":"get",
        		"data":function(d){
    				d.sku = $("#sku").val();
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{"data" : "id", "defaultContent" : ""},
				{"data" : "itemNo", "defaultContent" : ""},
				{"data" : "sku", "defaultContent" : ""},
                {"data" : "goodsName", "defaultContent" : ""},
				{"data" : "stock", "defaultContent" : ""},
				{"data" : "unit", "defaultContent" : ""},
				{"data" : "createTime", "defaultContent" : ""},
				{"data" : "updateTime", "defaultContent" : ""},
				{"data" : "qty", "defaultContent" : "","orderable":false,
                    "render": function (data, type, row) {
                                   var id = row['id'];
                                   var html=  "<input type=text name=qtys["+ row['id'] +"] value='' data_id="+row['id']+" class='layui-input item_qtys'  />";
                                   return html;
                                }},
                
            ],
           "order": [[ 0, "asc" ]]
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : '/pGoodsStocks/'+id,
            success : function(data) {
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}

$("#searchBt").click(function(){
	example.ajax.reload();
});

function resetForm(){
    $("#sku").val("");
    example.ajax.reload();
}


function saveOrderItems(type){
    var d={
        'type':type,
        'qtys': JSON.stringify(elementArray2Json($(".item_qtys")))
     };
     $.ajax({
        type : 'post',
        url : '/pGoodsStocks/saveAll',
        data : d,
        success : function(data) {
            if(type==1){
                layer.msg(data.message, {shift: -1, time: 1000}, function(){
                        location.href = "pGoodsStocksList.html";
                    });
            }else{
                layer.msg(data.message);
            }
        }
    });
}




init();
</script>
